﻿// -----------------------------------------------------------------------
// <copyright file="WebsiteConfig.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace NetFramework.Web.Configuration
{
    using System;
    using System.Xml.Serialization;

    using NetFramework.Collection;
    using NetFramework.Configuration;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    [ConfigFile("Configs/Website.config")]
    [XmlRoot("websiteConfig")]
    public class WebsiteConfig
    {
        private string domain = "";
        private KeyedCollection<UrlPathMapping> urlPathMappings = new KeyedCollection<UrlPathMapping>();

        /// <summary>
        /// 站点顶级域
        /// </summary>
        [XmlElement("domain")]
        public string Domain
        {
            get { return domain; }
            set { domain = value; }
        }

        /// <summary>
        /// 获取站点路径的集合
        /// </summary>
        [XmlArray("urlPathMappings")]
        [XmlArrayItem("add")]
        public KeyedCollection<UrlPathMapping> UrlPathMappings
        {
            get { return urlPathMappings; }
            set { urlPathMappings = value; }
        }

        #region Methods
        /// <summary>
        /// 获得Root Paths
        /// </summary>
        /// <param name="rootPathName"></param>
        /// <returns></returns>
        public string[] GetRootPaths(string rootPathName)
        {
            UrlPathMapping urlPathMapping = UrlPathMappings[rootPathName];

            if (urlPathMapping == null || urlPathMapping.Paths == null)
            {
                return null;
            }

            return urlPathMapping.Paths;
        }

        #endregion
    }
}
